import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  JoinColumn,
  Relation,
  ManyToMany,
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { User } from 'src/users/entities/user.entity';
import { Note } from './note.entity';
@Entity()
export class Tag {
  @ApiProperty({ description: '标签ID' })
  @PrimaryGeneratedColumn()
  id: number;
  @ApiProperty({ description: '标签名称' })
  @Column()
  name: string;
  // 标签创建者
  @ApiProperty({ description: '标签创建者', type: () => User })
  @ManyToOne(() => User)
  @JoinColumn({ name: 'user_id' })
  author: Relation<User>;
  // 标签创建时间
  @ApiProperty({ description: '标签创建时间' })
  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  create_time: Date;
  // 标签更新时间
  @ApiProperty({ description: '标签更新时间' })
  @Column({
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP',
    onUpdate: 'CURRENT_TIMESTAMP',
  })
  update_time: Date;
  // 标签所属笔记
  @ApiProperty({ description: '标签所属笔记', type: () => [Note] })
  @ManyToMany(() => Note, (note) => note.tags)
  notes: Note[];
}
